defs/util: Add functions to assign (compiler friendly) an int to a pointer and back.
authoroliskoli <oliskoli>
Thu, 21 Aug 2008 22:01:43 +0000 (22:01 +0000)
committeroliskoli <oliskoli>
Thu, 21 Aug 2008 22:01:43 +0000 (22:01 +0000)
defs.h
util.c

diff --git a/defs.h b/defs.h
index 4f774cd8bd0370f8a9dddd2696138a8a19201fac..891d4cd9e982f6bdadf298a251da79ca908bf709 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -951,6 +951,9 @@ typedef enum {
 char gb_getbit(const void *buf, const gbuint32 nr);
 void gb_setbit(void *buf, const gbuint32 nr);
 
+void *gb_int2ptr(const int i);
+int gb_ptr2int(const void *p);
+
 /*
  *  From parse.c
  */
diff --git a/util.c b/util.c
index 175f42750439c8ee39a3d08686cd94eb63b7d47a..4fdd2bb7c522c4c310ee477f6bd4c643f4705c67 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1760,3 +1760,30 @@ char gb_getbit(const void *buf, const gbuint32 nr)
        return (bytes[nr / 8] & (1 << (nr % 8)));
        
 }
+
+/*
+ * gb_int2ptr: Needed, when sizeof(*void) != sizeof(int) ! compiler warning !
+ */
+void *gb_int2ptr(const int i)
+{
+       union {
+               void *p;
+               int i;
+       } x = { NULL };
+
+       x.i = i;
+       return x.p;
+}
+
+/*
+ * gb_ptr2int: Needed, when sizeof(*void) != sizeof(int) ! compiler warning !
+ */
+int gb_ptr2int(const void *p)
+{
+       union {
+               const void *p;
+               int i;
+       } x = { p };
+
+       return x.i;
+}